package com.atguigu.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 使用继承HttpServlet类的方法去实现Servlet程序
 *
 * 1.编写一个类去继承HttpServlet类
 *
 * 2.根据业务需要重写doGet或doPost方法
 *
 * 3.到web.xml中的配置Servlet程序的访问地址
 *
 * 4.在配置文件中进行配置
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2021-12-04-16:23 16:23
 */
public class HelloServlet2 extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);//不要省略，在父类GenericServlet中init进行config的赋值，可以利用getServletConfig()来进行获取
        System.out.println("---通过继承的HttpServlet来获取的init()--");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGet-----start");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doPost-----start");
    }
}
